<template>
<div>
  <div class="m-det-warp mb30">
    <div class="m-det-tit">业务单号：{{data.BbMain.BBillNo}}</div>
    <div class="m-det-list">
      <ul class="m-det-ul">
        <li class="displayflex">
          <span class="label">制单日期</span>
          <div class="flex1 value">{{data.BbMain.BillDate | GetDate}}</div>
        </li>
        <li class="displayflex">
          <span class="label">司机</span>
          <div class="flex1 value">{{data.Vehicle.Driver1Name}} </div>
        </li>
        <li class="displayflex">
          <span class="label">司机电话</span>
          <div class="flex1 value">{{data.Vehicle.Driver1Tel}}</div>
        </li>
      </ul>
    </div>
  </div>

  <uploader :title="'回执单上传'" :img-list="imgList" :max="max"></uploader>

  <div class="m-form-wrap">
    <popup-picker class="m-form-box" title="差异原因" :data="reasonList" v-model="reason" @on-change="onChange" placeholder="请选择"></popup-picker>
      
    <div class="m-form-box"> 
        <span class="txt">备注</span>
        <div class="m-form-ipt">
            <textarea type="text" placeholder="请输入备注信息" v-model="Memo" style="font-size:16px"></textarea>
        </div>
    </div>
  </div>
  <div class="checknum-bot displayflex">
    <div class="num">共<em class="red">{{TotalCounts}}</em>件商品</div>
    <div class="flex1">
      <ul class="cf cn-btn-grp f-r">
        <li class="btn-checknum f-l cancel" @click="cancel()">取消</li>
        <li class="btn-checknum f-l" @click="Confirm()">收货完成</li>
      </ul>
    </div>
  </div>
</div>
</template>

<script>
import uploader from '@/components/share/imageUploader/imageUploader.vue';

export default{
  components:{
    uploader,
  },
  data(){
    return {
      reasonList:[],
      reason:[],

      max:9,
      data:{},
      todolist: [],
      imgList:[],

      Memo:'',
      ReceiverID:'',
      ReceiverName:'',
      PRContactsTel:'',
      TotalCounts:0,
    }
  },
  created(){
    this.getData();
  },
  beforeDestroy() {
    sessionStorage.removeItem('GoodsList');
    sessionStorage.removeItem('order');
    sessionStorage.removeItem('TotalCounts');
  },
  methods:{
    onChange(){

    },
    getData(){
      if(!sessionStorage.GoodsList || !sessionStorage.order || !sessionStorage.TotalCounts){
          let self = this;
          this.$vux.toast.show({
            text: '数据已过期，请重试',
            type: 'warn',
            onHide () {
              self.$router.go(-1)
            }
          });
      } else {
        var userinfo = JSON.parse(localStorage.userinfo);
        this.ReceiverID = userinfo.StaffID;
        this.ReceiverName = userinfo.Name;
        this.PRContactsTel = userinfo.MobileNo;
        this.goodslist = JSON.parse(sessionStorage.GoodsList);
        this.data = JSON.parse(sessionStorage.order);
        this.TotalCounts = sessionStorage.TotalCounts;
        this.getReason();
      }
    },
    getReason(){
      this.reasonList = [];
      let query = {
        TypeValue: 'Refusalreason'
      };
      this.Ajax.post('GetDatadictionaries', query).then((res) => {
        if(res.IsSuccess){
          let args = ['请选择'];
          res.Datas.forEach((x) => {
            args.push(x.DataIntroduction);
          })
          this.reasonList.push(args);
        } else {
          this.Toast(res.ErrorMessage);
        }
      })
      .catch((e) => {
        this.Toast('出错了，请刷新重试')
      })
    },

    Confirm() {
      this.goodslist.forEach((x) => {
        this.data.VehicleExies.forEach((y) => {
          if(x.GoodsGuid == y.GoodsGuid) {
            x.BBillRowNo = y.BBillRowNo;
            x.BBillGuid = x.Guid;
          }
        })
      });

      let imgList = [];
      this.imgList.forEach((x) => {
        let item = x.split(',')[1];
        imgList.push(item)
      })

      let query = {
        GUID: this.data.BbMain.Guid,
        imgurla: imgList,
        PKGS: this.data.BbMain.Pkgs,
        Weight: this.data.BbMain.Weight,
        Volumn: this.data.BbMain.Volume,
        //RowNo: this.data.VehicleDetail[0].RowNo,
        Memo: this.Memo,
        Receiver: this.ReceiverID,
        ReceiverName: this.ReceiverName,
        PRContactsTel: this.PRContactsTel,
        goodslist: this.goodslist,
        ExpReason: this.reason[0],
      };
      if(query.ExpReason == '请选择') {
        query.ExpReason = '';
      };

      console.log(query)

      this.Ajax.post('ReceivingConfirm', query).then((res) => {
        if(res.IsSuccess){
          let self = this;
          this.$vux.toast.show({
            text: '收货成功',
            type: 'success',
            onHide () {
              self.$router.replace({
                path:'/index'
              })
            }
          });
        } else {
          this.Toast(res.ErrorMessage);
        }
      })
      .catch((e) => {
        this.Toast('出错了，请刷新重试')
      })
    },


    cancel(){
      this.$router.replace({
        path:'/index'
      })
    },
  }
}
</script>